var navtab;
function openNavTab(data){
	navtab.tabAdd(data);
}
layui.config({
    base: 'static/new/js/'
}).use(['navtab'], function () {
    window.jQuery = window.$ = layui.jquery;
    window.layer = layui.layer;

    var element = layui.element;
    navtab = layui.navtab({
        elem: '.larry-tab-box'
    });

    //iframe自适应
    $(window).on('resize', function () {
        var $content = $('#larry-tab').find('.layui-tab-content');
        $content.height($(this).height() - 140);
        $content.find('iframe').each(function () {
            $(this).height($content.height());
        });
    }).resize();

    function leftSideEvent(){
        var $side = $('#larry-nav-side');
        if ($side.attr('lay-filter') !== undefined) {
            element.init();
            $side.children('ul').find('li').each(function () {
                var $this = $(this);
                if ($this.find('dl').length > 0) {
                    $this.find('dd').each(function () {
                        $(this).off().on('click', function () {
                        	
                        	if($(this).find('dl').length > 0){
                        		if($(this).find('dl').is(':visible'))
                    			{
                        			$(this).find('dl').show("fast");
                            		$(this).addClass('layui-nav-itemed');
                            		
                    			}else{
                    				$(this).removeClass('layui-nav-itemed');
                    				$(this).find('dl').hide("fast");
                    			}
                        		
                        		return;
                        		
                        	}
                        	
                            $(this).siblings('dd').removeClass('layui-this');
                            $(this).addClass('layui-this');

                            var $a = $(this).children('a');
                            var href = $a.data('url');
                            var icon = $a.children('i:first').data('icon');
                            var title =  $a.children('span').text();
                            if($a.children('span').text().length > 6){
                                title = $a.children('span').text().slice(0,6)+'...';
                            }
                            var title_msg = $a.children('span').text();
                            var data = {
                                href: href,
                                icon: icon,
                                title: title,
                                title_msg:title_msg
                            };
                            
                            navtab.tabAdd(data);
                        });
                    });
                } else {
                    $this.off().on('click', function () {
                        var $a = $(this).children('a');
                        var href = $a.data('url');
                        var icon = $a.children('i:first').data('icon');
                        var title = $a.children('span').text();
                        var data = {
                            href: href,
                            icon: icon,
                            title: title
                        };
                        navtab.tabAdd(data);
                    });
                }
            });
        }
    }
    leftSideEvent();
    $("#topRightMenu a").click(function(){
        var href = $(this).data("url");
        var title = $(this).attr("title");
        var data = {
            href: href,
            icon: "",
            title: title,
            title_msg:title
        };
        if(title !="退出"){
        	navtab.tabAdd(data);
        }
    })
    layui.use(['jquery', 'layer', 'element'], function () {
        window.jQuery = window.$ = layui.jquery;
        window.layer = layui.layer;
        // var element = layui.element();

        // larry-side-menu向左折叠
        $('.larry-side-menu').click(function () {
            var $larrySide = $('#larry-side');
            var sideWidth = $larrySide.width();
            if (sideWidth === 200) {
                $('#larry-body').animate({
                    left: '0'
                });
                $('#larry-footer').animate({
                    left: '0'
                });
                $larrySide.animate({
                    width: '0'
                });
            } else {
                $('#larry-body').animate({
                    left: '200px'
                });
                $('#larry-footer').animate({
                    left: '200px'
                });
                $larrySide.animate({
                    width: '200px'
                });
            }
        });
    });


    //生成菜单
    // var menuItem = Vue.extend({
    //     name: 'menu-item',
    //     props: {item: {}},
    //     template: [
    //         '<li class="layui-nav-item">',
    //         '<a v-if="item.type === 0" href="javascript:;">',
    //         '<i v-if="item.icon != null" :class="item.icon"></i>',
    //         '<span>{{item.name}}</span>',
    //         '<em class="layui-nav-more"></em>',
    //         '</a>',
    //         '<dl v-if="item.type === 0" class="layui-nav-child">',
    //         '<dd v-for="item in item.list">',
    //         '<a v-if="item.type === 1" href="javascript:;" :data-url="item.url"><i v-if="item.icon != null" :class="item.icon" :data-icon="item.icon"></i> <span>{{item.name}}</span></a>',
    //         '</dd>',
    //         '</dl>',
    //         '<a v-if="item.type === 1" href="javascript:;" :data-url="item.url"><i v-if="item.icon != null" :class="item.icon" :data-icon="item.icon"></i> <span>{{item.name}}</span></a>',
    //         '</li>'
    //     ].join('')
    // });

    //注册菜单组件
    // Vue.component('menuItem', menuItem);

    // noinspection JSUnusedGlobalSymbols
    /*var vm = new Vue({
        el: '#layui_layout',
        data: {
            user: {},
            menuList: {},
            password: '',
            newPassword: '',
            navTitle: "控制台"
        },
        methods: {
            getMenuList: function () {
                /!*var _this = this;
                $.getJSON("sys/menu/nav?_" + $.now(), function (r) {
                    vm.menuList = r.menuList;

                    _this.$nextTick(function () {
                        leftSideEvent();
                    });
                });*!/
            },
            getUser: function () {
                /!*$.getJSON("sys/user/info?_" + $.now(), function (r) {
                    vm.user = r.user;
                });*!/
            }/!*,
            updatePassword: function () {
                layer.open({
                    type: 1,
                    skin: 'layui-layer-molv',
                    title: "修改密码",
                    area: ['550px', '270px'],
                    shadeClose: false,
                    content: jQuery("#passwordLayer"),
                    btn: ['修改', '取消'],
                    btn1: function (index) {
                        var data = "password=" + vm.password + "&newPassword=" + vm.newPassword;
                        $.ajax({
                            type: "POST",
                            url: "sys/user/password",
                            data: data,
                            dataType: "json",
                            success: function (result) {
                                if (result.code === 0) {
                                    layer.close(index);
                                    layer.alert('修改成功', function () {
                                        location.reload();
                                    });
                                } else {
                                    layer.alert(result.msg);
                                }
                            }
                        });
                    }
                });
            }*!/
        },
        created: function () {
            this.getMenuList();
            this.getUser();
        }
    });*/
});




